Cross Development

Since CHICKEN generates C code, it is relatively easy to create programs and libraries for a different architecture than the one the compiler is executing on, a process commonly called cross compiling. Basically you can simply compile Scheme code to C and then invoke your target-specific cross compiler. To automate the process of invoking the correct C compiler with the correct settings and to simplify the use of extensions, CHICKEN can be built in a special "cross-compilation" mode.

Note: in the following text we refer to the "target" as being the platform on which the software is intended to run in the end. We use the term "host" as the system that builds this software. Others use a different nomenclature or switch the meaning of the words.

Preparations

Make sure you have a cross-toolchain in your PATH. In this example, a Linux system is used to generate binaries for an ARM based embedded system.

Building the target libraries

First you need a version of the runtime system (libchicken), compiled for the target system. Obtain and unpack a tarball of the CHICKEN sources, or check out the code from the official code repository, then build the libraries and necessary development files:

make ARCH= \
    PREFIX=/usr \
    PLATFORM=linux \
    HOSTSYSTEM=arm-none-linux-gnueabi \
    DESTDIR=$HOME/target \
    TARGET_FEATURES="-no-feature x86 -feature arm" \
    install

This will build CHICKEN and install it in ~/target, which we use as a temporary place to store the target files. A few things to note:

(cond-expand
  (x86 <do this ...>)
  ...)

You should now have these files on ~/target:

|-- bin
|   |-- chicken
|   |-- chicken-bug
|   |-- chicken-install
|   |-- chicken-profile
|   |-- chicken-status
|   |-- chicken-uninstall
|   |-- csc
|   `-- csi
|-- include
|   |-- chicken-config.h
|   `-- chicken.h
|-- lib
|   |-- chicken
|   |   `-- 9
|   |       :
|   |
|   |-- libchicken.a
|   |-- libchicken.so -> libchicken.so.9
|   `-- libchicken.so.9
`-- share
    |-- chicken
    |   |-- doc
    :   ;   :
    |   |
    |   `-- setup.defaults
    `-- man
        `-- man1
            :

You should now transfer ~/target/usr/lib to the target system, and place its contents in /usr/lib. You may want to omit the static library libchicken.a if the target memory is limited.

Building the "cross chicken"

Next, we will build another chicken, one that uses the cross C compiler to generate target-specific code that uses the target-specific runtime library we have just built.

Again, unpack a CHICKEN release tarball or a source tree and run make(1) once again:

make PLATFORM=linux \
    PREFIX=$HOME/cross-chicken \
    TARGETSYSTEM=arm-none-linux-gnueabi \
    PROGRAM_PREFIX=arm- \
    TARGET_PREFIX=$HOME/target/usr \
    TARGET_RUN_PREFIX=/usr \
    install

In ~/cross-chicken, you should find the following:

|-- bin
|   |-- arm-chicken
|   |-- arm-chicken-install
|   |-- arm-chicken-profile
|   |-- arm-chicken-status
|   |-- arm-chicken-uninstall
|   |-- arm-csc
|   `-- arm-csi
|-- include
|   |-- chicken-config.h
|   `-- chicken.h
|-- lib
|   |-- chicken
|   |   `-- 9
|   |       :
|   |
|   |-- libchicken.a
|   |-- libchicken